#{extends 'Content/ContentDetail.html'/}
#{set 'moreStyles'}
        #{stylesheet 'bootstrap.css' /}
#{/set}
#{set 'moreScripts'}
        #{script 'ckeditor/ckeditor.js' /}
#{/set}

#{if flash.error}
	<h2>${flash.error}</h2>
#{/if}
#{if user}
<div>
	<form action="@{Content.update()}" method="POST" enctype="multipart/form-data">
		<input type="hidden" name="id" value="${content.id}"/>
		<input type="hidden" name="description" value=""/>
        <fieldset>
          <legend>Chỉnh Sửa Nội Dung</legend>
          
           <div class="clearfix">
            <label for="mediumSelect">Chủ Đề</label>
            <div class="input">
              <select id="category" name="category" class="medium">
               	#{list items: categories, as:'category'}
				 <option value="${category?.alias}">${category?.name}</option>
				#{/list}
              </select>
            </div>
          </div>
          
          <div class="clearfix">
            <label for="xlInput">Tiêu Đề</label>
            <div class="input">
              <input type="text" size="30" name="title" value="${content.title}" id="title" class="xlarge">
            </div>
          </div><!-- /clearfix -->
         
                 
          <div class="clearfix">
            <label for="textarea">Nội Dung</label>
            <div class="input">
              <textarea rows="3" name="ckeditor" id="ckeditor">${content.description.raw()}</textarea>
              <span class="help-block">
                Block of help text to describe the field above if need be.
              </span>
            </div>
          </div><!-- /clearfix -->
          
          <div class="clearfix">
            <label id="optionsCheckboxes">Ẩn Danh</label>
            <div class="input">
              <ul class="inputs-list">
                <li>
                  <label>
                    <input type="checkbox" id="invisible" name="invisible" ${content.invisible == true ?'checked':''}>
                    <span>Bạn muốn ẩn nick khi gởi bài viết</span>
                  </label>
                </li>
              </ul>
            </div>
          </div>
          
          <div class="actions">
            <input type="submit" value="Cập Nhập" class="btn primary" onclick="checkForm()">&nbsp;<button class="btn" type="reset">Hủy Bỏ</button>
          </div>
        </fieldset>
      </form>
      <script type="text/javascript">
		      function checkForm(){
					var flag = true;
					title = jQuery('input[name="title"]').val();
					check_accept = jQuery('input[name="check_accept"]').attr('checked');
					if(title.length == 0){
						alert("vui lòng nhập thông tin chủ đề");
						flag = false;
						return flag;
					}
					flag = updateContent();
					if(!flag){
						alert("vui lòng nhập nội dung");
						return flag;
					}
					return flag;
				}
      
      		var editor = CKEDITOR.replace('ckeditor');
      		function updateContent(){
				var oEditor = CKEDITOR.instances.ckeditor;
				var pageValue = oEditor.getData();
				if(pageValue.length > 0){
					$('input[name=description]').val(pageValue);
					return true;
				}
				return false;
				//alert(pageValue);
			}
			function setSelect(){
				jQuery('select').val('${content.category}');
			}
			setSelect();
      </script>
</div>
#{/if}
#{else}
	<a href="@{Application.login()}" class="big"><img src="@{'/public/images/login.jpeg'}" alt="picture"/>
            <h2>Login with Gmail</h2></a>
#{/else}